<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="产品" prop="keyword">
          <el-input v-model="filterForm.keyword" clearable placeholder="产品ID/产品标题/产品内容" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="下单时间" prop="orderTime">
          <el-date-picker 
          clearable
            v-model="filterForm.orderTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker 
          clearable
            v-model="filterForm.payTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付方式" prop="payType">
            <el-radio-group v-model="filterForm.payType">
              <el-radio-button label="0">全部</el-radio-button>
              <el-radio-button label="1">支付宝</el-radio-button>
              <el-radio-button label="2">微信</el-radio-button>
              <el-radio-button label="3">银行卡</el-radio-button>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-radio-group v-model="filterForm.status">
              <el-radio-button label="0">全部</el-radio-button>
              <el-radio-button label="1">已处理</el-radio-button>
              <el-radio-button label="2">待处理</el-radio-button>
              <el-radio-button label="3">处理中</el-radio-button>
            </el-radio-group>
        </el-form-item>
      </el-form>
      <el-button @click="handleFilter()">搜索</el-button>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      @sort-change="sortChange"
    >
      <el-table-column
      type="selection"
      width="55">
    </el-table-column>
      <el-table-column label="产品" min-width="200px">
        <template slot-scope="{row}">
          <div @click="handleOrderDetailButton(row)">{{ row.orderCode }}</div>
          <div>{{ row.productName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="客户" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.customer.fullname }}</span>
          <span>{{ row.customer.mobile }}</span>
        </template>
      </el-table-column>
      <el-table-column label="份额" min-width="150px">
        <template slot-scope="{row}">
          <div>{{ row.quantity }}</div>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.settlement.settlementName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下单/支付时间" min-width="150px">
        <template slot-scope="{row}">
          <div>{{ row.orderCreateTime }}</div>
          <div>{{ row.orderPayTime }}</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.orderStatus.label }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="200px">
        <template slot-scope="{row}">
            <el-button type="text" @click="hiddenDepositWrapper=true;depositForm.accountID=row.ID" >删除</el-button>
            <el-button type="text" @click="hiddenDepositWrapper=true;depositForm.accountID=row.ID" >备注</el-button>
            <el-button type="text" @click="hiddenRefundWrapper=true;" >退款</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />

<el-dialog
  title="申请退款"
  :visible.sync="hiddenRefundWrapper"
  width="30%"
  :before-close="handleRefundClose">
  <el-form :model="refundForm">
    <el-form-item label="活动名称">
      <el-input v-model="refundForm.name"></el-input>
    </el-form-item>
    <el-form-item label="退还金额">
      <el-input v-model="refundForm.refundAmount"></el-input>
    </el-form-item>
    <el-form-item label="退还原因">
      <el-input v-model="refundForm.refundReason"></el-input>
    </el-form-item>
    <el-form-item label="备注">
      <el-input v-model="refundForm.remark"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="hiddenRefundWrapper = false">取 消</el-button>
    <el-button type="primary" @click="hiddenRefundWrapper = false">确 定</el-button>
  </div>
</el-dialog>
  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getOrderList} from '@/api/fund/order'

export default {
  name: 'faultinessAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      socket:"",
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
      hiddenRefundWrapper:false,
      refundForm:{},
      connected:"loading",
      depositForm:{
        amount:100
      },
      hiddenDepositWrapper:false,
      filterForm: {
        page: 1,
        size: 10,
        simulation: 2,
        status: '0'
      }
    }
  },
  created() {
    this.getList()
  },
  
  methods: {
    getList:function(){
      let _this = this;
      console.log(_this.filterForm)
      getOrderList(_this.filterForm).then((response) => {
        console.log(response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleOrderDetailButton:function(order){
        this.$router.push({ path: 'order-detail', query: { 'orderCode': order.orderCode }})
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    handleRefundClose:function(){

    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    }
  }
}
</script>
<style>

</style>